﻿/* ***********************************************
 * Author		:  kingthy
 * Email		:  kingthy@gmail.com
 * Description	:  OpenTObject
 *
 * ***********************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using OpenTwitter.SDK.Http;
using System.Xml;

namespace OpenTwitter.SDK.Http
{
    /// <summary>
    /// WEB请求
    /// </summary>
    public class WebRequest
    {
        /// <summary>
        /// 
        /// </summary>
        internal WebRequest()
        {
            this.Headers = new Parameters();
            this.Parameters = new Parameters();
            this.Files = new Files();
            this.Charset = Encoding.UTF8;
        }
        /// <summary>
        /// 编码
        /// </summary>
        public Encoding Charset { get; set; }
        /// <summary>
        /// HTTP头
        /// </summary>
        protected Parameters Headers { get; private set; }
        /// <summary>
        /// 提交的参数
        /// </summary>
        protected Parameters Parameters { get; private set; }
        /// <summary>
        /// 要上传的文件
        /// </summary>
        protected Files Files { get; private set; }

        /// <summary>
        /// 操作中最后一次发生的错误
        /// </summary>
        public Exception LastError { get; private set; }
        /// <summary>
        /// 清除错误
        /// </summary>
        protected void ClearError()
        {
            this.LastError = null;
        }
        /// <summary>
        /// 出现错误
        /// </summary>
        /// <param name="exception"></param>
        protected void OnError(Exception exception)
        {
            this.LastError = exception;
        }

        /// <summary>
        /// 清除参数
        /// </summary>
        protected void Clear()
        {
            this.ClearError();
            this.Headers.Clear();
            this.Parameters.Clear();
            this.Files.Clear();
        }
    }
}
